package itheima.springbootwebdemo.web;

import itheima.springbootwebdemo.pojo.Address;
import itheima.springbootwebdemo.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ResponseController {

    //响应普通字符串
    @RequestMapping("/hellos")
    public Result hello() {
        return Result.error("请求失败");
    }


    //响应实体对象
    @RequestMapping("/getAdd")
    public Result getAdd() {
        Address address = new Address();
        address.setProvince("河南");
        address.setCity("信阳");
        return Result.success(address);
    }


    //响应集合对象
    @RequestMapping("/listAdd")
    public Result listAdd() {
        ArrayList<Address> listadd = new ArrayList<>();
        Address address1 = new Address();
        address1.setProvince("河南");
        address1.setCity("信阳");
        Address address2 = new Address();
        address2.setProvince("河南");
        address2.setCity("商丘");
        listadd.add(address1);
        listadd.add(address2);
        return Result.success(listadd);
    }
}
